package ebook.location.chapter_1_thread;

import java.util.concurrent.TimeUnit;

/**
 * description: <br>
 * createTime: 2020/5/2915:26 <br>
 *
 * @author zzh
 */
public class ThreadTest {
    Object obj1 = new Object();
    Object obj2 = new Object();
    public void run1() throws InterruptedException {
        synchronized (obj1) {
            run2();
        }
    }


    private void run2() throws InterruptedException {
        synchronized (obj2) {
            while(true) {
                TimeUnit.MILLISECONDS.sleep(500);
                System.out.println("-");
            }
        }
    }


    public static void main(String[] args) throws InterruptedException {
//        new Thread(() -> {
//            try {
//                TimeUnit.SECONDS.sleep(2);
//                StringBuilder sb = new StringBuilder();
//                Map<Thread, StackTraceElement[]> allStackTraces = Thread.getAllStackTraces();
//                for (Map.Entry<Thread, StackTraceElement[]> entry : allStackTraces.entrySet()) {
//                    sb.append(entry.getKey()).append("\n");
//                    for (StackTraceElement element : entry.getValue()) {
//                        sb.append(element).append("\n");
//                    }
//                    sb.append("----------------------------").append("\n");
//                }
//                System.out.println(sb.toString());
//                System.exit(0);
//            } catch (InterruptedException e) {
//                e.printStackTrace();
//            }
//        }).start();
        ThreadTest test = new ThreadTest();
        test.run1();
    }
}
